# -*- coding: utf-8 -*-

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core import urlresolvers
from django.contrib.auth.models import User
from django.conf import settings
from game.models.utils import check_new_ants
from game.models.utils import *

class Ant(models.Model):

    CH_TYPE = (
        ('W', u'Worker'),
        ('OO', u'Ordinary Offensive'),
        ('OD', u'Ordinary Defensive'),
        ('FO', u'Fly Offensive'),
        ('FD', u'Fly Defensive'),
        ('Q', u'Queen'),
    )

    CH_POSITION = (
        ('C', u'Camera'),
        ('M', u'Moving'),
    )

    type_ant = models.CharField(verbose_name=_(u'Type ant'), max_length=6,
                                blank=False, null=False, choices=CH_TYPE)
    base = models.ForeignKey('game.Base', verbose_name="It is in a base",
                             blank=False, null=False, related_name='ants_base')
    player = models.ForeignKey('game.Player', verbose_name="Player owner",
                               blank=False, null=False,
                               related_name='ants_player')
    position = models.CharField(verbose_name=_(u'Position'), max_length=2,
                                blank=False, null=False, choices=CH_POSITION)
    in_movement_resources = models.ForeignKey('game.MovementResources',
                                        verbose_name="Ant in Resource Movement",
                                        blank=True, null=True,
                                        related_name='movement_ants')
    in_attack = models.ForeignKey('game.Attack', verbose_name="Ant in Attack",
                                  blank=True, null=True,
                                  related_name='attack_ants')
    in_uphold = models.ForeignKey('game.Uphold', verbose_name="Ant in Uphold",
                                  blank=True, null=True,
                                  related_name='uphold_ants')
    date_created = models.DateTimeField(verbose_name=_(u'Created Date'),
                                        null=True, auto_now_add=True)
    date_updated = models.DateTimeField(verbose_name=_(u'Updated Date'),
                                        null=True, auto_now=True)


    class Meta:
        app_label = 'game'
        verbose_name = _(u'Ant')
        verbose_name_plural = _(u'Ants')


    def __unicode__(self):
        return unicode(self.id) + u' -- ' + unicode(self.get_type_ant_display()) + u' -- ' + unicode(self.player.name)


    def save(self, *args, **kwargs):
        if not self.id:
            check_new_ants(type_ant, 1, self.base)
        super(Ant, self).save(*args, **kwargs)

